#include "gtest/gtest.h"
#include <mockcpp/mokc.h>
#include <mockcpp/mockcpp.hpp>

#include <vector>
#include <iostream>
#include <sys/types.h>
#include <sys/wait.h>

#include "topoinfo_struct.h"
#include "log.h"
#include "checker.h"
#include "virtual_topo.h"
#include "testcase_utils.h"

using namespace hccl;

class CmdTest : public testing::Test {
protected:
    static void SetUpTestCase()
    {
        std::cout << "CmdTest set up." << std::endl;
    }

    static void TearDownTestCase()
    {
        std::cout << "CmdTest tear down." << std::endl;
    }

    virtual void SetUp()
    {
        const ::testing::TestInfo* const test_info = ::testing::UnitTest::GetInstance()->current_test_info();
        std::string caseName = "analysis_result_" + std::string(test_info->test_case_name()) + "_" + std::string(test_info->name());
        Checker::SetDumpFileName(caseName);
    }

    virtual void TearDown()
    {
        Checker::SetDumpFileName("analysis_result");
        GlobalMockObject::verify();
        // 这边每个case执行完成需要清理所有的环境变量，如果有新增的环境变量，需要在这个函数中进行清理
        ClearHcclEnv();
    }
};

TEST_F(CmdTest, testcase_cmd)
{
    char curDir[1024];
    if (getcwd(curDir, sizeof(curDir)) != NULL){
        std::cout << "Current working dir : " << curDir << std :: endl;
    } else {
        std::cout << "getcwd error" << std :: endl;
    }
    system("../output/llt/hccl_lib/hccl_alg_analyzer_test -p 2 -s 1 -r 1 -d 910_93 -t reduce -o max -b 500m -e 500m -n int8");
    system("../output/llt/hccl_lib/hccl_alg_analyzer_test -p 2 -s 1 -r 4 -d 910_93 -t reduce -b 1G -e 1G -n int32");
    system("../output/llt/hccl_lib/hccl_alg_analyzer_test -p 2 -s 1 -r 4 -d 910_93 -t broadcast -b 500m -e 500m -n int8 -r 1");
    system("../output/llt/hccl_lib/hccl_alg_analyzer_test -p 1 -s 1 -r 1 -d 910 -t allreduce -b 1G -e 2G -n fp16 -o min");
    system("../output/llt/hccl_lib/hccl_alg_analyzer_test -p 1 -s 1 -r 2 -d 910 -t send -b 500m -e 5g -n int8");
    system("../output/llt/hccl_lib/hccl_alg_analyzer_test -p 1 -s 1 -r 2 -d 910 -t receive -b 500m -e 4g -n int8");
    system("../output/llt/hccl_lib/hccl_alg_analyzer_test -p 1 -s 2 -r 8 -d 910 -t allgather -b 1g -e 1g -n int32");
    system("../output/llt/hccl_lib/hccl_alg_analyzer_test -p 1 -s 2 -r 2 -d 910_93 -t reducescatter -b 5g -e 5g -n int64");
    system("../output/llt/hccl_lib/hccl_alg_analyzer_test -p 1 -s 1 -r 1 -d 910_93 -t alltoallv -b 500m -e 500m -n int8");
    system("../output/llt/hccl_lib/hccl_alg_analyzer_test -p 1 -s 1 -r 2 -d 910_93 -t alltoall -b 500m -e 500m -n int8");
    system("../output/llt/hccl_lib/hccl_alg_analyzer_test -p 1 -s 1 -r 4 -d 910_93 -t alltoallvc -b 500m -e 500m -n int8");
    system("../output/llt/hccl_lib/hccl_alg_analyzer_test -p 1 -s 1 -r 4 -d 910_93 -t scatter -b 1024 -e 2048 -n int8");
    system("../output/llt/hccl_lib/hccl_alg_analyzer_test -p 1 -s 1 -r 2 -d 910_93 -t batchsendrecv -b 1G -e 2G -n int8");
    system("../output/llt/hccl_lib/hccl_alg_analyzer_test -p 1 -s 1 -r 8 -d 310p3 -t allgatherv -b 4G -e 4G -n int32");
}